package com.roc.web.action.agent;

import java.util.ArrayList;
import java.util.List;

import com.roc.page.BaseSearchCondition;
import com.roc.page.WhereHQLFieldBean;
import com.roc.util.Constance;

/**
 * 终端分配
 * @author zx-think
 *
 */
public class SerialNumQueryCondition extends BaseSearchCondition {
	
	
	private String orgCode;//机构
	private String posBrand;//品牌
	private String posType;//机型
	private String posName;//名称
	private String isUsed;//是否出库
	private long agentId;//归属商ID
	private String serialNum;//POS序列号
	
	public String getOrgCode() {
		return orgCode;
	}

	public void setOrgCode(String orgCode) {
		this.orgCode = orgCode;
	}

	public String getPosBrand() {
		return posBrand;
	}

	public void setPosBrand(String posBrand) {
		this.posBrand = posBrand;
	}

	public String getPosType() {
		return posType;
	}

	public void setPosType(String posType) {
		this.posType = posType;
	}

	public String getPosName() {
		return posName;
	}

	public void setPosName(String posName) {
		this.posName = posName;
	}
	

	public String getIsUsed() {
		return isUsed;
	}

	public void setIsUsed(String isUsed) {
		this.isUsed = isUsed;
	}
	
	public long getAgentId() {
		return agentId;
	}

	public void setAgentId(long agentId) {
		this.agentId = agentId;
	}
	

	public String getSerialNum() {
		return serialNum;
	}

	public void setSerialNum(String serialNum) {
		this.serialNum = serialNum;
	}

	@Override
	protected String getOrderPartOfHQL() {
		// TODO Auto-generated method stub
		return " order by pos.SERIAL_NUM,pos.IS_USED ASC ";
	}

	@Override
	protected String getRowCountHQL() {
		return " select count(*) from (select a.serial_num,a.pos_brand,a.pos_type,a.pos_name,b.is_used,a.dt_create,a.dt_lastmod,b.agent_id  from yj_pos_info a,yj_pos_agent b where  a.serial_num = b.serial_num and a.pos_brand = b.pos_brand and b.is_used = 'N' and a.tek_id = 'Y' ) pos "
				+ " where not exists (select * from tbl_term_inf tt where tt.device_cd=pos.serial_num and tt.TMNL_BRAND = pos.pos_brand) ";
	}

	@Override
	protected String getSearchHQL() {
		String hql = " select serial_num,pos_brand,pos_type,pos_name,is_used,dt_create,dt_lastmod from ( "
				+ " select a.serial_num,a.pos_brand,a.pos_type,a.pos_name,b.is_used,a.dt_create,a.dt_lastmod,b.agent_id  from yj_pos_info a,yj_pos_agent b where  a.serial_num = b.serial_num and a.pos_brand = b.pos_brand and b.is_used = 'N' and a.tek_id = 'Y' "
				+ " ) pos where not exists (select * from tbl_term_inf tt where tt.device_cd=pos.serial_num and tt.TMNL_BRAND = pos.pos_brand) ";
		return hql;
	}

	@Override
	protected List<WhereHQLFieldBean> getWhereHQLFieldBeanList() {
		// TODO Auto-generated method stub
		List<WhereHQLFieldBean> filedBeanList = new ArrayList<WhereHQLFieldBean>();
		
			filedBeanList.add(new WhereHQLFieldBean("pos.agent_Id", agentId, "=", false));
		
		if (Constance.isNotEmpty(posBrand) && !posBrand.equals("-1")) {
			filedBeanList.add(new WhereHQLFieldBean("pos.pos_Brand", posBrand.trim(), "=", false));
		}
		if (Constance.isNotEmpty(posType) && !posType.equals("-1")) {
			filedBeanList.add(new WhereHQLFieldBean("pos.pos_Type", posType.trim(), "=", false));
		}
		if (Constance.isNotEmpty(posName) && !posName.equals("-1")) {
			filedBeanList.add(new WhereHQLFieldBean("pos.pos_Name", posName.trim(), "=", false));
		}
		if (Constance.isNotEmpty(isUsed)) {
			filedBeanList.add(new WhereHQLFieldBean("pos.is_Used", isUsed.trim(), "=", false));
		}
		if (Constance.isNotEmpty(serialNum)) {
			filedBeanList.add(new WhereHQLFieldBean("pos.SERIAL_NUM", serialNum.trim(), "=", false));
		}
		
		return filedBeanList;
	}

}
